package org.nokatag.code;

import java.util.ArrayList;
import java.util.Iterator;

public class TextString
{

    private ArrayList characters;

    public TextString()
    {
        characters = new ArrayList();
    }

    public void clear()
    {
        characters.clear();
    }

    public void addCharacter(TextCharacter tc)
    {
        characters.add(tc);
    }

    public ArrayList getCharacters()
    {
        return characters;
    }

    public double getWidth()
    {
        double minx = 0.0D;
        double maxx = 0.0D;
        boolean first = true;
        Iterator i$ = characters.iterator();
        do
        {
            if(!i$.hasNext())
            {
                break;
            }
            TextCharacter tc = (TextCharacter)i$.next();
            if(first)
            {
                minx = tc.getX();
                maxx = tc.getX() + tc.getWidth();
                first = false;
            } else
            {
                if(minx > tc.getX())
                {
                    minx = tc.getX();
                }
                if(maxx < tc.getX() + tc.getWidth())
                {
                    maxx = tc.getX() + tc.getWidth();
                }
            }
        } while(true);
        return maxx - minx;
    }

    public double getHeight()
    {
        double miny = 0.0D;
        double maxy = 0.0D;
        boolean first = true;
        Iterator i$ = characters.iterator();
        do
        {
            if(!i$.hasNext())
            {
                break;
            }
            TextCharacter tc = (TextCharacter)i$.next();
            if(first)
            {
                miny = tc.getY();
                maxy = tc.getY() + tc.getHeight();
                first = false;
            } else
            {
                if(miny > tc.getY())
                {
                    miny = tc.getY();
                }
                if(maxy < tc.getY() + tc.getHeight())
                {
                    maxy = tc.getY() + tc.getHeight();
                }
            }
        } while(true);
        return maxy - miny;
    }
}
